package com.cn.jinl.controller;


import com.cn.jinl.api.IOnDutyReduceService;
import com.cn.jinl.domain.OnDutyReduce;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/reduce")
public class OnDutyReduceController {

    @Autowired
    private IOnDutyReduceService onDutyReduceService;

    @RequestMapping("/getOnDutyReduceList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OnDutyReduce>> getOnDutyReduceList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<OnDutyReduce>> response = new JsonResponse<>();
        List<OnDutyReduce> onDutyReduces = onDutyReduceService.getOnDutyReduceList(queryForm);
        response.setResult(onDutyReduces);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getOnDutyReduceDetailList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OnDutyReduce>> getOnDutyReduceDetailList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<OnDutyReduce>> response = new JsonResponse<>();
        List<OnDutyReduce> onDutyReduces = onDutyReduceService.getOnDutyReduceDetailList(queryForm);
        response.setResult(onDutyReduces);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/getOnDutyReduceCount/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,Integer>> getOnDutyReduceCount(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,Integer>> response = new JsonResponse<>();
        Map<String,Integer> onDutyReduces = onDutyReduceService.getOnDutyReduceCount();
        response.setResult(onDutyReduces);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/addOnDutyReduce/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addOnDutyWeek(OnDutyReduce onDutyReduce, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyReduceService.addOnDutyReduce(onDutyReduce);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateOnDutyReduce/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateOnDutyReduce(OnDutyReduce onDutyReduce, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyReduceService.updateOnDutyReduce(onDutyReduce);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateCheckOnDutyReduce/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateCheckOnDutyReduce(@RequestBody OnDutyReduce onDutyReduce, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyReduceService.updateCheckOnDutyReduce(onDutyReduce);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteOnDutyReduce/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteOnDutyReduce(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyReduceService.deleteOnDutyReduce(id);
        return CommonUtil.getResponseData(response,result);
    }


}
